<?php

abstract class Workset_Sphinx_Adapter_Abstract {

    protected $_profiler = null;

    protected $_defaultProfilerClass = 'Zend_Db_Profiler';

    abstract function query(Workset_Sphinx_Query_Interface $query);

    abstract function setOptions($options);

    abstract function getMeta();

    abstract function getTotal();

    public function setProfiler($profiler) {
        if ($profiler instanceof Zend_Db_Profiler) {
            $this->_profiler = $profiler;

        } elseif (true === $profiler) {
            $profilerClass = $this->_defaultProfilerClass;
            $this->_profiler = new $profilerClass();
            $this->_profiler->setEnabled(true);

        } elseif (is_array($profiler)) {
            $enabled = isset($profiler['enabled']) ? $profiler['enabled'] : false;
            $profiler = isset($profiler['profiler']) ? $profiler['profiler'] : null;

            if (!is_string($profiler)) {
                throw new Workset_Sphinx_Adapter_Exception('Profiler does not exists');
            }

            if (!class_exists($profiler)) {
                Zend_Loader::loadClass($profiler);
            }

            $this->_profiler = new $profiler();
            $this->_profiler->setEnabled($enabled);

        }

        return $this;

    }

    public function getProfiler() {
        return $this->_profiler;
    }

}